<?php 
class ItemDetail extends Module{
	function ItemDetail($row){
	    Module::Module($row);
		require_once 'core/se.php';		
		if(Item::$id == -1){
			Item::$id = (int)Url::get('id',0);
			
			Item::$item = Item::get_item(Item::$id);
		}
		
		AZLib::checkItem();
		
		if(Item::$item)
		{
			
			if(Item::$item['display'])
			{

				if(REWRITE_ON){//tuannk add 2010.07.28 fix redirect 301 với các url link sai
					$nice_name1 = '';
					if(Item::$item['category_id'] && isset(CGlobal::$allCategories[Item::$item['category_id']]) && CGlobal::$allCategories[Item::$item['category_id']]){
						$nice_name1 = CGlobal::$allCategories[Item::$item['category_id']]['nice_name'];
					}
		
					$url_detail = WEB_DIR.$nice_name1."/p".Item::$item['id']."/".AZLib::safe_title(Item::$item['name']).".html";
					
					if($nice_name1!='' && strpos($_SERVER['REQUEST_URI'],$url_detail) !==0 ){
						Url::redirect_url($url_detail,301);
					}
				}
				
				CGlobal::$website_title = Item::$item['name'];						
				CGlobal::$website_title .= ' - '.AZLib::titlePath(Item::$item['category_id']);	
									
				if(Item::$item['status'] == 2)
				{
					if(User::have_permit(ADMIN_ITEM))
						CGlobal::$website_title = 'Tin đang ẩn';
					else
						Item::$item['display']=0;
				}
				
				Item::update_read_count();
			}
		}
		
		require_once 'forms/ItemDetail.php';
		$this->add_form(new ItemDetailForm());
	}
}
?>